﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.EntityClient;
using SmartSpace.Core;

namespace SsTool
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //ConnectWindow window = new ConnectWindow();
            //if (window.ShowDialog() != true)
            //{
            //    this.Close();
            //}
        }

        private void MenuItemInstall_Click(object sender, RoutedEventArgs e)
        {
            this._ctlFrame.Navigate(new InstallPage());
        }

        private void MenuItemWorkflow_Click(object sender, RoutedEventArgs e)
        {
            this._ctlFrame.Navigate(new Workflow.WorkflowMetadataListPage());
        }

        private void MenuItemToDatabase_Click(object sender, RoutedEventArgs e)
        {
            this._ctlFrame.Navigate(new InstallPage());
        }

        private void MenuItemUserManagement_Click(object sender, RoutedEventArgs e)
        {
            this._ctlFrame.Navigate(new UserListPage());
        }

        private void MenuItemClick(object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;
            string pageClassName = item.Tag.ToString();

            this._ctlLabelTitle.Text = item.Header.ToString();
            this._ctlFrame.Navigate(GetPage(pageClassName));
        }

        private Page GetPage(string className)
        {
            if (!className.Contains("SsTool"))
            {
                object obj = this.GetType().Assembly.CreateInstance("SsTool." + className);
                return obj as Page;
            }
            else
            {
                object obj = this.GetType().Assembly.CreateInstance(className);
                return obj as Page;
            }
        }
    }
}
